package lzk.myshop.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lzk.myshop.Util.GoodsAdd;
import lzk.myshop.pojo.Users;
import lzk.myshop.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin(origins = "*")
@RequestMapping("/User")
@RestController
@Api("User interface")
public class UserController {
    @Autowired
    public UsersServiceImpl usersServiceImpl;

    @ApiOperation("用户登录接口,account:手机号/邮箱,password:密码")
    @GetMapping("/signIn")
    public Map<String,Object> signIn(String account, String password){
        return usersServiceImpl.signin(account,password);
    }

    @ApiOperation("用户注册，用户对象（邮箱、手机、密码（二次确认）、地址、姓名）")
    @PostMapping("/create")
    public Map<String,Object> create(Users users){
        return usersServiceImpl.addUser(users);
    }

    @ApiOperation("账号注销接口，delete请求，前端二次确认后传入userid")
    @DeleteMapping("/userDelete")
    public Map<String, Object> userDelete(int userID){
        return usersServiceImpl.deleteUser(userID);
    }
    @ApiOperation("主页浏览商品接口，Get请求，返回值是goods的集合，预计采用分页查询，待完善")
    @GetMapping("/getAllGoods")
    public Map<String,Object> getAllGoods(){
        return usersServiceImpl.allGoods();
    }

    @ApiOperation("查询商品接口，get请求，传入一个String，返回商品的集合，模糊搜索待完善")
    @GetMapping("/searchGoods")
    public Map<String,Object> searchGoods(String name){
        return usersServiceImpl.searchGoods(name);
    }

    @ApiOperation("添加商品到购物车的接口，post请求，传入商品id和数量，返回int，1代表成功，其余待定，待完善")
    @PostMapping("/addCart")
    public Map<String,Object> addCart(int cartid,int goodsID,int count){
        return usersServiceImpl.addCart(cartid,goodsID,count);
    }
    @ApiOperation("订单生成,ok")
    @PostMapping("/newOrder")
    public Map<String,Object> newOrderByCartId(int cartid){
        return usersServiceImpl.newOrderByCartId(cartid);
    }

    @ApiOperation("订单支付接口，该接口弃用，正确接口在AlipayController中")
    @PostMapping("/payCart")
    public void payCart(){}

    @ApiOperation("用户订单接口，查看所有订单，根据状态前端进行分类，未完成")
    @GetMapping("/allUserOrder")
    public Map<String,Object> allUserOrder(int userId){
        return usersServiceImpl.getAllOrder(userId);
    }

//    @ApiOperation("根据商品名字查询特定订单,返回的是订单集合，未完成")
//    @GetMapping("/getOrderByName")
//    public void getOrderByName(){
//
//    }

    @ApiOperation("取消未支付订单,传入订单号")
    @DeleteMapping("/deleteOrder")
    public Map<String,Object> deleteOrder(int id){
        return usersServiceImpl.deleteOrder(id);
    }

    @ApiOperation("修改手机号")
    @PostMapping("alterPhone")
    public Map<String,Object> alterPhone(String newPhone,int userid){
        return usersServiceImpl.alterPhone(newPhone,userid);
    }
    @ApiOperation("修改邮箱")
    @PostMapping("alterEmail")
    public Map<String,Object> alterEmail(String newEmail,int userid){
        return usersServiceImpl.alterEmail(newEmail,userid);
    }
    @ApiOperation("修改地址")
    @PostMapping("alterAddress")
    public Map<String,Object> alterAddress(String newAddress,int userid){
        return usersServiceImpl.alterAddress(newAddress,userid);
    }

    @ApiOperation("确认收货")
    @PostMapping("/getGoods")
    public Map<String,Object> getGoods(int OrderId){
        return usersServiceImpl.getGoods(OrderId);
    }

    @ApiOperation("查看购物车")
    @GetMapping("/getCart")
    public Map<String,Object> getCart(int cartid){
        return usersServiceImpl.getCart(cartid);
    }

    @ApiOperation("删除购物车商品")
    @PostMapping("/deleteCart")
    public Map<String,Object> deleteCart(int cartDetailid){
        return usersServiceImpl.deleteCart(cartDetailid);
    }
}
